package com.youease.chris.model.proxy
{
	import com.youease.chris.model.vo.MenuData;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	public class MenuDataProxy extends Proxy implements IProxy
	{
		public static const NAME:String = "MenuDataProxy";
		
		public function MenuDataProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		public function get menuData():MenuData {
			return this.data as MenuData;
		}
		
		public function enableMenuItem(data:String,enabled:Boolean=true):void {
			var find:Boolean = false;
			for each(var xml:XML in menuData.menuBarCollection) {
				var target:XML = findMenuItem(data,xml);
				if(target) {
					target.@enabled = enabled;
					find = true;
				}
			}
			if(!find) {
				trace("找不到这个菜单命令："+data);
			}
		}
		
		private function findMenuItem(data:String,xml:XML):XML {
			for each(var ele:XML in xml.children()) {
				if(ele.children().length()>0) {
					return findMenuItem(data,ele);
				}else {
					if(ele.@data==data) {
						return ele;
					}
				}
			}
			return null;
		}
	}
}